import { Injectable } from "@nestjs/common";
import { IAuthCaptchat } from "src/auth/auth.interface";
import svgCaptcha from "svg-captcha";
import { HelperStringService } from "./helper.string.service";

@Injectable()
export class HelperCaptchaService {
  constructor(
    private readonly helperStringService: HelperStringService
  ){}
  async randomCaptcha(config?: svgCaptcha.ConfigObject): Promise<IAuthCaptchat> {
    const svgData =  svgCaptcha.create({
      size: 4, // 个数
      width: 120, // 宽
      height: 30, // 高
      fontSize: 38, // 字体大小
      color: true, // 字体颜色是否多变
      background: '#f1f1f1',
      ...config
    })
    return {
      captchaId: this.helperStringService.random(20),
      captchaData: svgData.data,
      captchaValue: svgData.text
    }
  }
}
